package com.itqf.controller;

import com.itqf.entity.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/10/10
 * @Time: 上午11:36
 */
//@Controller
@RestController  // 所有方法都响应json
// @Controller+@ResponseBody
public class JsonController {


    @RequestMapping(value = "/findAll",produces ="application/json; charset=UTF-8" )
    //String  一般 跳页面 或者  执行另一个请求
    //一定要导入jackson包
    //@ResponseBody   //把方法返回的java对象--->json对象
    //User  Map
    public List<User> findAll(){
        List<User> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setId(i+1);
            user.setName("隔壁老王"+i);
            user.setBirthdate(new Date());

            list.add(user);
        }

        return  list;
    }


    @RequestMapping("/addUser")
    //@RequestBody   把前端传递的json字符串--->java对象
    public Map<String,Object>  addUser(@RequestBody User user){
        System.out.println(user);
        Map<String,Object> map = new HashMap<>();
        map.put("code",1);
        map.put("msg","新增成功");
        map.put("u",user);
        return  map;
    }





}
